<?php
/**
 * Created by PhpStorm.
 * User: Zhoujinda
 * Date: 2016/3/29
 * Time: 16:30
 */

namespace Api\Domain;


class LogDomain extends BaseDomain{

    protected $business_code = 'log';

    protected $allowType = array("json", "rss", "html");

    /**
 * 添加日志
 */

    public function add(){

        $this->checkVersion(100);
        addLog("Log/addLog",$_GET,$_POST,"应用" . $this->client_id . "调用添加日志接口");

        $notes = $this->_post('notes','','日志缺失');
        $notes_name = $this->_post('notes_name','','日志名称缺失');

        $model = M('ApiCallHis');

        $result = $model->create(array(
            'api_uri'=>$notes_name,
            'call_get_args'=>'',
            'call_post_args'=>$notes,
            'notes'=>'',
            'call_time'=>NOW_TIME,
        ));

        if($result){
            $info = $model->add();
            $this->apiReturnSuc($info);
        }

        $this->apiReturnErr('记录失败');

    }

    /**
     * 查询日志
     */

    public function query(){

        $this->checkVersion(100);
        addLog("Log/addLog",$_GET,$_POST,"应用" . $this->client_id . "调用查看日志接口");

        $notes_name = $this->_post('notes_name','','日志名称缺失');
        $notes = $this->_post('notes','');


        $model = M('ApiCallHis');

        $map = array(
            'api_uri' => array('like',"%$notes_name%"),
            'call_post_args' => array('like',"%$notes%"),
        );

        $result = $model->field('api_uri as notes_name,call_post_args as notes')->where($map)->order('call_time desc')->select();

        if($result){
           $this->apiReturnSuc($result);
        }

        $this->apiReturnErr('查询失败');

    }

}